#include<stdio.h>
#include<assert.h>

int Strstr(const char* str, const char* sub)
{
	assert(str != NULL && sub != NULL);

	int i = 0;
	int j = 0;
	while (str[i])
	{
		if (str[i] == sub[j])
		{
			i++;
			j++;
		}
		else
		{
			i = i - j + 1;
			j = 0;
		}

		if (sub[j] == '\0')
			return i - j;
	}

	return -1;
}

int main()
{
	printf("%d\n",Strstr("aaabcdef", "abc"));//2
	printf("%d\n",Strstr("aaabcdef", "abd"));//-1
	printf("%d\n", Strstr("aaabcdef", "aaa"));//0
	printf("%d\n",Strstr("abcababcabc", "abcabc"));//5

	return 0;
}

